package com.example.store2.Controller;

import com.example.store2.Service.UserService;
import com.example.store2.pojo.Result;
import com.example.store2.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 显示用户信息
     *
     * @param username
     * @return
     */
    @GetMapping
    public Result show(String username) {
        log.info("传入用户名为{}", username);
        User user = userService.show(username);
        return Result.success(user);
    }

    /**
     * 修改用户信息
     *
     * @param user
     */
    @PutMapping
    public Result update(@RequestBody User user) {
        log.info("user:{}", user);
        if (userService.update(user))
            return Result.success();
        else
            return Result.error("修改失败");
    }

}
